| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/filester/vendor-prefixed/src/Menu/ |
Upload File : |
<?php
namespace FilesterScoped\YayCommerce\AdminShell\Menu;
use FilesterScoped\YayCommerce\AdminShell\Support\AdminContext;
/**
* Applies the intended ordering to the YayCommerce submenu.
*
* WordPress treats add_submenu_page()'s $position as an array INSERTION INDEX,
* not an ordering rank, and silently appends any value >= the current submenu
* count. Sparse positions (e.g. 10, 20, 21, 40) therefore collapse to plugin
* load order. Rather than fight that at registration time (which can't be
* coordinated across already-shipped scoped copies), we let every plugin
* register however it likes, then reorder the FINAL assembled array once.
*
* Ownership: run only by the version-elected winner (via do_shell_registration),
* so a single authority orders ALL submenus — including those registered by
* older co-installed copies. Positions are read from a shared cross-scope map
* populated by AdminShell::register_plugin().
* @internal
*/
class SubmenuPositioner
{
const PARENT = 'yaycommerce';
const POSITION_KEY = 'yaycommerce_admin_shell_submenu_positions';
public function init() : void
{
// Priority 9999: run after every plugin (<=10) and TopLevelMenu's parent
// submenu cleanup (999) have finished, so the array is complete.
// Bound to both hooks so reordering also applies in Network Admin.
AdminContext::bind_menu([$this, 'reorder'], 9999);
}
/**
* Reorder $submenu['yaycommerce'] by declared position.
* Lower position first; ties and unknown/null positions keep their existing
* order and sort after positioned items.
*/
public function reorder() : void
{
global $submenu;
if (empty($submenu[self::PARENT]) || !\is_array($submenu[self::PARENT])) {
return;
}
$positions = $GLOBALS[self::POSITION_KEY] ?? [];
// Decorate with original index for a stable sort (usort is not stable
// before PHP 8.0). Item shape: [ menu_title, capability, menu_slug, ... ].
$decorated = [];
foreach ($submenu[self::PARENT] as $index => $item) {
$slug = $item[2] ?? '';
$decorated[] = ['item' => $item, 'index' => $index, 'position' => $positions[$slug] ?? null];
}
\usort($decorated, function ($a, $b) {
$pa = $a['position'];
$pb = $b['position'];
if (null === $pa && null === $pb) {
return $a['index'] <=> $b['index'];
}
if (null === $pa) {
return 1;
// unknown/null positions last
}
if (null === $pb) {
return -1;
}
if ($pa === $pb) {
return $a['index'] <=> $b['index'];
// stable tiebreak
}
return $pa <=> $pb;
});
// Re-index to sequential keys; WP renders the submenu in array order.
$submenu[self::PARENT] = \array_values(\array_column($decorated, 'item'));
}
}